//
//  MedicineCell.m
//  pocketmedicine
//
//  Created by student on 16/4/25.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "MedicineCell.h"
@interface MedicineCell()
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *idLabel;

@property (weak, nonatomic) IBOutlet UILabel *descriptionLabel;
@property (weak, nonatomic) IBOutlet UITextView *messageTextVIew;
@property (weak, nonatomic) IBOutlet UILabel *tagLabel;

@property (weak, nonatomic) IBOutlet UILabel *typeLabel;
@property (weak, nonatomic) IBOutlet UILabel *countLabel;

@property (weak, nonatomic) IBOutlet UILabel *factoryLabel;


@end
@implementation MedicineCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (void)setMedicine:(MedicineModel *)medicine
{
    _medicine = medicine;
    
    self.iconImageView.image = [UIImage imageNamed:medicine.img];
    
    [self getImage];
    self.nameLabel.text = medicine.name;
    self.idLabel.text =[NSString stringWithFormat:@"%ld",medicine.medicineId ];
    self.descriptionLabel.text = medicine.description1;
    self.messageTextVIew.text = medicine.message;
    self.tagLabel.text = medicine.tag;
    self.typeLabel.text = medicine.type;
    self.countLabel.text = [NSString stringWithFormat:@"%d",medicine.count];
    self.factoryLabel.text = medicine.factory;
    self.messageTextVIew.editable = NO;
 
 
}

- (void)getImage
{
    NSString *urlStr = [[NSString alloc] init];
    if([_medicine.img hasPrefix:@"http"] )
    {
          urlStr = [NSString stringWithFormat:@"%@",_medicine.img];
    }
    else
    {
        urlStr = [NSString stringWithFormat:@"http://tnfs.tngou.net/img%@",_medicine.img];
    
    }
    NSLog(@"%@",urlStr);
    NSURL *url = [NSURL URLWithString:urlStr];
    NSData *data = [NSData dataWithContentsOfURL:url];
    UIImage *image = [UIImage imageWithData:data];
    self.iconImageView.image = image;
}


@end
